package com.vctgo.currency.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.currency.domain.TbCurrency;
import com.vctgo.currency.service.ITbCurrencyService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 币别Controller
 *
 * @author vctgo
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/currency")
public class TbCurrencyController extends BaseController
{
    @Autowired
    private ITbCurrencyService tbCurrencyService;


    /**
     * 查询币别列表
     */
    @RequiresPermissions("currency:currency:list")
    @GetMapping("/list")
    public AjaxResult list(TbCurrency tbCurrency)
    {
        IPage<TbCurrency> list = tbCurrencyService.selectTbCurrencyPage(tbCurrency);
        return AjaxResult.success(list);
    }

    /**
     * 导出币别列表
     */
    @RequiresPermissions("currency:currency:export")
    @Log(title = "币别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCurrency tbCurrency)
    {
        List<TbCurrency> list = tbCurrencyService.selectTbCurrencyList(tbCurrency);
        ExcelUtil<TbCurrency> util = new ExcelUtil<TbCurrency>(TbCurrency.class);
        util.exportExcel(response, list, "币别数据");
    }

    /**
     * 获取币别详细信息
     */
    @RequiresPermissions("currency:currency:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCurrencyService.selectTbCurrencyById(id));
    }

    /**
     * 新增币别
     */
    @RequiresPermissions("currency:currency:add")
    @Log(title = "币别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCurrency tbCurrency)
    {

        return toAjax(tbCurrencyService.insertTbCurrency(tbCurrency));
    }

    /**
     * 修改币别
     */
    @RequiresPermissions("currency:currency:edit")
    @Log(title = "币别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCurrency tbCurrency)
    {
        return toAjax(tbCurrencyService.updateTbCurrency(tbCurrency));
    }

    /**
     * 删除币别
     */
    @RequiresPermissions("currency:currency:remove")
    @Log(title = "币别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCurrencyService.deleteTbCurrencyByIds(ids));
    }
}
